home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_222 / plplot / src / source.zoo / plcntr.c < prev    next >
C/C++ Source or Header  |  1989-05-15  |  6KB  |  207 lines

  1. /* Contour "ny" by "nx" real array "points" at the level "zlev" */
  2. /* points is a pointer to a 2d array of nx by ny points. */
  3. /* iscan has nx elements. ixstor and iystor each have nstor elements. */
  4.  
  5. #include "plplot.h"
  6.  
  7. void plcntr(points,nx,ny,kx,lx,ky,ly,zlev,iscan,ixstor,iystor,nstor,tr)
  8. int nx, ny, ky, ly, kx, lx, nstor;
  9. float zlev, *points;
  10. int iscan[], ixstor[], iystor[];
  11. void (*tr)();
  12. {
  13.       int kcol, krow, kstor, kscan, iwbeg, ixbeg, iybeg, izbeg;
  14.       int iboun, iw, ix, iy, iz, ifirst, istep, ixgo, iygo;
  15.       int l, ixg, iyg, ia, ib, ixt, iyt, jstor, next;
  16.       float dist, dx, dy, xnew, ynew, x, y;
  17.       float xlas=0., ylas=0., tpx, tpy, xt, yt;
  18.  
  19.       /* Initialize memory pointers */
  20.  
  21.       kstor = 0;
  22.       kscan = 0;
  23.  
  24.       for (krow=ky; krow<=ly; krow++) {
  25.         for (kcol=kx+1; kcol <= lx; kcol++)  {
  26.  
  27.           /* Check if a contour has been crossed */
  28.  
  29.           x = *(points + (kcol-2)*ny + krow-1);
  30.           y = *(points + (kcol-1)*ny + krow-1);
  31.           if (x < zlev && y >= zlev) {
  32.             ixbeg = kcol-1;
  33.             iwbeg = kcol;
  34.           }
  35.           else if (y < zlev && x >= zlev) {
  36.             ixbeg = kcol;
  37.             iwbeg = kcol-1;
  38.           }
  39.           else
  40.             goto lab70;
  41.  
  42.           iybeg = krow;
  43.           izbeg = krow;
  44.  
  45.           /* Yes, a contour has been crossed. Check to see if it */
  46.           /* is a new one. */
  47.  
  48.           for(l=0;l<kscan;l++)
  49.             if (ixbeg == iscan[l]) goto lab70;
  50.  
  51.           /* Here is the section which follows and draws a contour */
  52.  
  53.           for (iboun=1; iboun>= -1; iboun -= 2) {
  54.  
  55.             /* Set up starting point and initial search directions */
  56.  
  57.             ix = ixbeg;
  58.             iy = iybeg;
  59.             iw = iwbeg;
  60.             iz = izbeg;
  61.             ifirst = 1;
  62.             istep = 0;
  63.             ixgo = iw - ix;
  64.             iygo = iz - iy;
  65.  
  66. lab20:
  67.               plccal(points,nx,ny,zlev,ix,iy,ixgo,iygo,&dist);
  68.               dx = dist * ixgo;
  69.               dy = dist * iygo;
  70.               xnew = ix+dx;
  71.               ynew = iy+dy;
  72.  
  73.              /* Has a step occured in search? */
  74.  
  75.               if (istep != 0) {
  76.                 if (ixgo*iygo == 0) {
  77.  
  78.                   /* This was a diagonal step, so interpolate missed */
  79.                   /* point, rotating 45 degrees to get it */
  80.  
  81.                   ixg = ixgo;
  82.                   iyg = iygo;
  83.                   plr45(&ixg,&iyg,iboun);
  84.                   ia = iw-ixg;
  85.                   ib = iz-iyg;
  86.                   plccal(points,nx,ny,zlev,ia,ib,ixg,iyg,&dist);
  87.                   (*tr)(xlas,ylas,&tpx,&tpy);
  88.                   drawor(tpx,tpy);
  89.                   dx = dist*ixg;
  90.                   dy = dist*iyg;
  91.                   xlas = ia+dx;
  92.                   ylas = ib+dy;
  93.                 }
  94.                 else {
  95.                   if (dist > 0.5) {
  96.                     xt = xlas;
  97.                     xlas = xnew;
  98.                     xnew = xt;
  99.                     yt = ylas;
  100.                     ylas = ynew;
  101.                     ynew = yt;
  102.                   }
  103.                 }
  104.               }
  105.               if (ifirst != 1) {
  106.                 (*tr)(xlas,ylas,&tpx,&tpy);
  107.                 drawor(tpx,tpy);
  108.               }
  109.               else {
  110.                 (*tr)(xnew,ynew,&tpx,&tpy);
  111.                 movwor(tpx,tpy);
  112.               }
  113.               xlas = xnew;
  114.               ylas = ynew;
  115.  
  116.               /* Check if the contour is closed */
  117.  
  118.               if (ifirst != 1 && ix == ixbeg && iy == iybeg
  119.                   && iw == iwbeg && iz == izbeg) {
  120.                 (*tr)(xlas,ylas,&tpx,&tpy);
  121.                 drawor(tpx,tpy);
  122.                 goto lab70;
  123.               }
  124.               ifirst = 0;
  125.  
  126.               /* Now the rotation */
  127.  
  128.               istep = 0;
  129.               plr45(&ixgo,&iygo,iboun);
  130.               iw = ix+ixgo;
  131.               iz = iy+iygo;
  132.  
  133.               /* Check if out of bounds */
  134.  
  135.               if (iw<kx || iw>lx || iz<ky || iz>ly) goto  lab50;
  136.  
  137.               /* Has contact been lost with the contour? */
  138.  
  139.               if (*(points+(iw-1)*ny+iz-1) < zlev) {
  140.  
  141.                 /* Yes, lost contact => step to new centre */
  142.  
  143.                 istep = 1;
  144.                 ix = iw;
  145.                 iy = iz;
  146.                 plr135(&ixgo,&iygo,iboun);
  147.                 iw = ix+ixgo;
  148.                 iz = iy+iygo;
  149.  
  150.                 /* And do the contour memory */
  151.  
  152.                 if (iy == krow) {
  153.                   kscan = kscan+1;
  154.                   iscan[kscan-1] = ix;
  155.                 }
  156.                 else if (iy>krow) {
  157.                   kstor = kstor+1;
  158.                   if (kstor>nstor) {
  159.                     fatal("Heap exhausted in PLCONT.");
  160.                     goto lab70;
  161.                   }
  162.                   ixstor[kstor-1] = ix;
  163.                   iystor[kstor-1] = iy;
  164.                 }
  165.               }
  166.             goto lab20;
  167. lab50:
  168.             /* Reach here only if boundary encountered - Draw last bit */
  169.  
  170.             (*tr)(xnew,ynew,&tpx,&tpy);
  171.             drawor(tpx,tpy);
  172.           }
  173. lab70:
  174.           ;    /* Null statement to carry label */
  175.         }
  176.  
  177.         /* Search of row complete - set up memory of next row in iscan and */
  178.         /* edit ixstor and iystor */
  179.  
  180.         if (krow<ny) {
  181.           jstor = 0;
  182.           kscan = 0;
  183.           next = krow+1;
  184.           for (l=1; l<=kstor; l++) {
  185.             ixt = ixstor[l-1];
  186.             iyt = iystor[l-1];
  187.  
  188.             /* Memory of next row into iscan */
  189.  
  190.             if (iyt == next) {
  191.               kscan = kscan+1;
  192.               iscan[kscan-1] = ixt;
  193.       
  194.             /* Retain memory of rows to come, and forget rest */
  195.  
  196.             }
  197.             else if (iyt>next) {
  198.               jstor = jstor+1;
  199.               ixstor[jstor-1] = ixt;
  200.               iystor[jstor-1] = iyt;
  201.             }
  202.           }
  203.           kstor = jstor;
  204.         }
  205.       }
  206. }
  207.